(function(t){if(t.JCIblockVoteStars)return;t.JCIblockVoteStars=function(t){this.progressObj=null;this.ratingObj=null;this.starsObj=null;this.progressId="";this.ratingId="";this.starsId="";this.ajaxParams={};this.siteId="";this.voteData={element:0,percent:0,count:0};this.config={readOnly:false,alreadyVoted:true,request:false};if(BX.type.isPlainObject(t)){if(BX.type.isNotEmptyString(t.progressId))this.progressId=t.progressId;if(BX.type.isNotEmptyString(t.ratingId))this.ratingId=t.ratingId;if(BX.type.isNotEmptyString(t.starsId))this.starsId=t.starsId;if(BX.type.isNotEmptyString(t.ajaxUrl))this.ajaxUrl=t.ajaxUrl;if(BX.type.isNotEmptyString(t.checkVoteUrl))this.checkVoteUrl=t.checkVoteUrl;if(BX.type.isPlainObject(t.ajaxParams))this.ajaxParams=t.ajaxParams;if(BX.type.isNotEmptyString(t.siteId))this.siteId=t.siteId;if(BX.type.isPlainObject(t.voteData)){if(BX.type.isNumber(t.voteData.element))this.voteData.element=t.voteData.element;if(BX.type.isNumber(t.voteData.percent))this.voteData.percent=this.preparePercent(t.voteData.percent);if(BX.type.isNumber(t.voteData.count))this.voteData.count=t.voteData.count}if(BX.type.isBoolean(t.readOnly))this.config.readOnly=t.readOnly}BX.ready(BX.proxy(this.init,this))};t.JCIblockVoteStars.prototype.init=function(){if(BX.type.isNotEmptyString(this.progressId))this.progressObj=BX(this.progressId);if(BX.type.isNotEmptyString(this.ratingId))this.ratingObj=BX(this.ratingId);if(BX.type.isNotEmptyString(this.starsId))this.starsObj=BX(this.starsId);this.showProgress(this.voteData.percent);this.showVotes();this.checkVote()};t.JCIblockVoteStars.prototype.checkVote=function(){if(this.config.readOnly||this.voteData.element<=0)return;BX.ajax({timeout:30,method:"POST",dataType:"json",url:this.checkVoteUrl,data:{sessid:BX.bitrix_sessid(),checkVote:"Y",vote_id:this.voteData.element,site_id:this.siteId},onsuccess:BX.proxy(this.checkVoteResult,this)})};t.JCIblockVoteStars.prototype.checkVoteResult=function(t){if(BX.type.isPlainObject(t)){if(t.success)this.config.alreadyVoted=t.voted}if(this.config.readOnly||this.config.alreadyVoted||this.voteData.element<=0)return;if(BX.type.isElementNode(this.starsObj)){BX.bind(this.starsObj,"mousemove",BX.proxy(this.handlerMouseMove,this));BX.bind(this.starsObj,"mouseout",BX.proxy(this.handlerMouseOut,this));BX.bind(this.starsObj,"click",BX.proxy(this.handlerClick,this))}};t.JCIblockVoteStars.prototype.destroy=function(){if(BX.type.isElementNode(this.progressObj))BX.unbindAll(this.progressObj);this.progressObj=null;if(BX.type.isElementNode(this.ratingObj))BX.unbindAll(this.ratingObj);this.ratingObj=null;if(BX.type.isElementNode(this.starsObj))BX.unbindAll(this.starsObj);this.starsObj=null};t.JCIblockVoteStars.prototype.preparePercent=function(t){t=parseInt(t,10);if(isNaN(t))t=0;else if(t>100)t=100;else if(t<0)t=0;return t};t.JCIblockVoteStars.prototype.showProgress=function(t){if(!BX.type.isElementNode(this.progressObj))return;BX.style(this.progressObj,"width",t.toString()+"%")};t.JCIblockVoteStars.prototype.showVotes=function(){if(!BX.type.isElementNode(this.ratingObj))return;this.ratingObj.innerHTML="( "+this.voteData.count+" )"};t.JCIblockVoteStars.prototype.handlerMouseMove=function(e){var s,i;if(this.config.readOnly||this.config.alreadyVoted||this.config.request)return;e=e||t.event;if(!BX.type.isElementNode(this.starsObj))return;s=BX.pos(this.starsObj);i=(e.pageX-s.left)/s.width*5;this.showProgress(this.preparePercent(Math.ceil(i)*20))};t.JCIblockVoteStars.prototype.handlerMouseOut=function(){if(this.config.readOnly||this.config.alreadyVoted||this.config.request)return;this.showProgress(this.voteData.percent)};t.JCIblockVoteStars.prototype.handlerClick=function(e){var s,i;if(this.config.readOnly||this.config.alreadyVoted||this.config.request)return;this.config.request=true;e=e||t.event;if(!BX.type.isElementNode(this.starsObj))return;s=BX.pos(this.starsObj);i=parseInt(Math.ceil((e.pageX-s.left)/s.width*5),10);if(isNaN(i))return;this.ajaxParams.rating=i-1;this.ajaxParams.vote="Y";this.ajaxParams.vote_id=this.voteData.element;this.ajaxParams.sessid=BX.bitrix_sessid();this.ajaxParams.site_id=this.siteId;BX.ajax({timeout:30,method:"POST",dataType:"json",url:this.ajaxUrl,data:this.ajaxParams,onsuccess:BX.proxy(this.clickResult,this)})};t.JCIblockVoteStars.prototype.clickResult=function(t){this.config.request=false;if(BX.type.isPlainObject(t)){this.config.alreadyVoted=true;this.voteData.percent=this.preparePercent(t.value*20);this.voteData.count=t.votes;this.showProgress(this.voteData.percent);this.showVotes()}}})(window);
//# sourceMappingURL=script.map.js